package com.gtw.memento.manyState;

/**
 * 通过clone方式,自我实现备忘录功能
 * 注意:
 *      使用在比较简单的场景中,尽量不要与其他对象产生严重的耦合
 */
public class ManyStateOriginator{

    private String state1;
    private String state2;
    private String state3;

    /**
     * 全属性备份
     */
    public Mementor createMementor(){
        return new Mementor(BeanUtils.backupProp(this));
    }

    //恢复备忘录
    public void restoreMementor(Mementor mementor){
        //进行恢复前应该进行断言,防止空指针
        BeanUtils.restoreProp(this, mementor.getStateMap());
    }

    public String getState1() {
        return state1;
    }

    public void setState1(String state1) {
        this.state1 = state1;
    }

    public String getState2() {
        return state2;
    }

    public void setState2(String state2) {
        this.state2 = state2;
    }

    public String getState3() {
        return state3;
    }

    public void setState3(String state3) {
        this.state3 = state3;
    }

    @Override
    public String toString() {
        return "ManyStateOriginator{" +
                "state1='" + state1 + '\'' +
                ", state2='" + state2 + '\'' +
                ", state3='" + state3 + '\'' +
                '}';
    }
}
